package com.graduation.books_borrow.repository;

import com.graduation.books_borrow.entity.BooksBorrow;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BooksBorrowMapper{

    @Insert("insert into books_borrow(book_id, user_id, status, addtime, comment) values(#{bookId}, #{userId}, #{status}, #{addtime}, #{comment})")
    boolean bookBorrow(BooksBorrow booksBorrow);

    @Select("select id, book_id, user_id, status, addtime, comment from books_borrow where book_id = #{bookId} and status = 1 limit 1")
    BooksBorrow bookBorrowQuery(BooksBorrow booksBorrow);

    @Select("select id, book_id, user_id, status, addtime, comment from books_borrow where user_id = #{userId} and status = 1")
    List<BooksBorrow> bookBorrowQueryByUserId(BooksBorrow booksBorrow);

    @Select("select id, book_id, user_id, status, addtime, comment from books_borrow where user_id = #{userId} and book_id = #{bookId} and status = 1 limit 1")
    BooksBorrow bookBorrowQueryByUserIdBookId(BooksBorrow booksBorrow);

    @Update("update books_borrow set status = 0 where user_id = #{userId} and book_id = #{bookId}")
    int bookReturn(BooksBorrow booksBorrow);

    @Update("update books set borrow_status = #{status} where id = #{bookId}")
    boolean bookBorrowStatusUpdate(@Param("bookId") String bookId, @Param("status") int status);

}
